<!-- 大屏列表 -->
<template>
  <div class="main-layout">
    <!-- 新增弹窗start -->
    <el-dialog
      title="新增大屏"
      :visible.sync="dialogVisible"
      custom-class="dialogStyle"
      width="30%"
    >
      <el-form
        ref="addForm"
        :model="addParams"
        :rules="rules"
        label-width="auto"
        destroy-on-close
      >
        <el-form-item label="大屏名称" prop="title">
          <el-input
            v-model="addParams.title"
            size="mini"
            clearable
            placeholder="请输入大屏名称"
          />
        </el-form-item>
        <el-form-item label="大屏宽度" prop="width">
          <el-input
            v-model="addParams.width"
            size="mini"
            clearable
            placeholder="请输入大屏宽度"
          />
        </el-form-item>
        <el-form-item label="大屏高度" prop="height">
          <el-input
            v-model="addParams.height"
            size="mini"
            clearable
            placeholder="请输入大屏高度"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="createBigscreen('addForm')"
          >确 定</el-button
        >
        <el-button @click="dialogVisible = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 弹窗end -->
    <div class="navbg">
      <el-input placeholder="请输入大屏名称" v-model="params.name" class="input-with-select">
        <el-button slot="append" icon="el-icon-search" @click="search('form')"></el-button>
      </el-input>

      <div class="checkobx">
        <el-checkbox-group v-model="params.status" @change="handleCheckChange">
          <el-checkbox label="0">已保存</el-checkbox>
          <el-checkbox label="1">已发布</el-checkbox>
          <el-checkbox label="2">已删除</el-checkbox>
        </el-checkbox-group>
      </div>
    </div>
    <!-- 列表 -->
    <div class="contadd">
      <div class="content__add" @click="dialogVisible = true">
        <img src="@/assets/images/new-project.png" height="40px" alt="" />
        <p>新建大屏</p>
      </div>
      <!-- 分页 -->
      <div class="block">
        <el-pagination
          :total="totalCount"
          :page-sizes="[8, 20, 50, 100]"
          :page-size="params.pageSize"
          :current-page="params.pageNumber"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>

    <el-row v-if="list.length !== 0" :gutter="20" style="margin: 20px; overflow:hidden">
      <div class="content__item" v-for="item in list" :key="item.id" style="margin:0 20px 20px 0; float: left">
        <div class="content__info">
          <img
            v-if="item.content.coverImg"
            :src="item.content.coverImg"
            alt=""
            class="jietu"
          />
          <img
            v-else
            src="../../assets/images/bigbg.jpg"
            alt=""
          />
          <div class="title">{{ item.content.dashboard.title }}</div>
          <div class="time">{{ item.last_udt_dt || item.create_tm }}</div>
          <!-- <div class="content__menu">
            <div class="content__btn">编辑</div>
            <div class="content__btn">导出</div>
          </div> -->
        </div>
        <div class="content__main">
          <!-- <span class="content__name">数据大屏模板</span> -->
          <div class="content__menulist">
            <div class="content__view">
              <div class="operation">
                <el-tooltip class="item" effect="dark" content="删除" placement="bottom">
                  <el-button
                    icon="el-icon-delete"
                    class="view"
                    type="text"
                    @click="handleDesign(item, 'del')"
                  />
                </el-tooltip>
                <el-tooltip class="item" effect="dark" content="预览" placement="bottom">
                  <el-button
                    icon="el-icon-view"
                    class="view"
                    type="text"
                    @click="jumpDesign(item, 'view')"
                  />
                </el-tooltip>
                <el-tooltip class="item" effect="dark" content="编辑" placement="bottom">
                  <el-button
                    icon="el-icon-edit"
                    class="edit"
                    type="text"
                    @click="jumpDesign(item, 'edit')"
                  />
                </el-tooltip>
                <el-tooltip class="item" effect="dark" content="发布" placement="bottom">
                  <el-button
                    icon="el-icon-s-promotion"
                    class="edit"
                    type="text"
                    @click="handleDesign(item, 'publish')"
                  />
                </el-tooltip>
                <el-tooltip class="item" effect="dark" content="复制" placement="bottom">
                  <el-button
                    icon="el-icon-document-copy"
                    class="edit"
                    type="text"
                    @click="handleCopy(item, 'copy')"
                  />
                </el-tooltip>
                <span>
                  {{ item.status ===  '0' ? '已保存' : item.status ===  '1' ? '已发布' : '已删除'}}
                </span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </el-row>
  </div>
</template>

<script>
import { reportPageList, editBigscreen, copyBigscreen } from "@/api/bigscreen";
import { mapState } from "vuex";
export default {
  name: "bigscreen",
  data() {
    return {
      list: [],
      rules: {
        title: [
          { required: true, message: "请输入大屏名称", trigger: "change" },
        ],
        width: [
          { required: true, message: "请输入大屏宽度", trigger: "change" },
        ],
        height: [
          { required: true, message: "请输入大屏高度", trigger: "change" },
        ],
      },
      totalCount: 0, // 分页总条数
      dialogVisible: false,
      // 查询列表参数
      params: {
        name: "",
        status: ['0','1'],
        pageNumber: 1,
        pageSize: 8,
      },
      // 新建大屏参数
      addParams: {
        title: "",
        width: "1920",
        height: "1080",
      },
    };
  },
  computed: {
    ...mapState("user", ["userInfo"]),
  },
  mounted() {
    this.queryByPage();
  },
  methods: {
    // 查询
    search() {
      this.params.pageNumber = 1;
      this.queryByPage();
    },
    // 查询接口
    queryByPage() {
      const loading = this.$loading({
        lock: true,
        text: "正在加载中，请稍后",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });
      reportPageList({
        prov_cd: this.userInfo.prov_cd,
        city_cd: this.userInfo.city_cd,
        zon_cd: this.userInfo.zon_cd,
        name: this.params.name,
        status: this.params.status,
        pagination: {
          current: this.params.pageNumber,
          pageSize: this.params.pageSize,
        },
      }).then((res) => {
        if (res.tx_status != "00") return;

        this.list = res.list_grp.map((item) => ({
          ...item,
          content: JSON.parse(item.content || ""),
        }))
        // .filter((item) => item.status !== "2");
        this.totalCount = res.pagination.total;
      }).finally(() => {
        loading.close();
      })
    },
    // 筛选
    handleCheckChange() {
      this.queryByPage();
    },
    // 重置
    reset(formName) {
      this.$refs[formName].resetFields();
      this.params.name = "";
      this.params.pageNumber = 1;
      this.queryByPage();
    },
    // 分页size
    handleSizeChange(val) {
      this.params.pageSize = val;
      this.queryByPage();
    },
    // 分页current
    handleCurrentChange(val) {
      this.params.pageNumber = val;
      this.queryByPage();
    },
    // 删除status => 0保存，1发布，2删除
    async handleDesign(item, type) {
      this.$confirm(`确定${type === "del" ? "删除" : "发布"}此大屏配置吗?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const loading = this.$loading({
          lock: true,
          text: `正在${type === "del" ? "删除" : "发布"}中，请稍后`,
          spinner: "el-icon-loading",
          background: "rgba(0, 0, 0, 0.7)",
        });
        editBigscreen({
          lgc_sn: item.lgc_sn,
          status: type === "del" ? "2" : "1",
        }).then(res => {
          if (res.tx_status === "00") {
            this.$message.success(`大屏${type === "del" ? "删除" : "发布"}成功！`);
            this.queryByPage();
          } else {
            this.$message.error(res.error_info.msg || "请求失败");
          }
        }).finally(() => {
          loading.close();
        })
      })
    },
    // 大屏跳转
    jumpDesign(val, type) {
      var routeUrl = this.$router.resolve({
        path: type === 'edit' ? `/micro/vueApply/out/bigscreen/designer/${val.lgc_sn}` : `/micro/vueApply/out/bigscreen/viewer/${val.lgc_sn}`,
      });
      window.open(routeUrl.href, "_blank");
    },
    // 新增大屏
    createBigscreen() {
      this.$refs['addForm'].validate((valid) => {
        if (valid) {
          let routeUrl = this.$router.resolve({
            path: "/micro/vueApply/out/bigscreen/designer/new",
            query: {
              title: this.addParams.title,
              width: this.addParams.width,
              height: this.addParams.height,
            },
          });
          window.open(routeUrl.href, "_blank");
          this.dialogVisible = false;
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    // 复制
    handleCopy(item) {
      this.$confirm(`确定复制此大屏配置吗?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const loading = this.$loading({
          lock: true,
          text: `正在复制中，请稍后`,
          spinner: "el-icon-loading",
          background: "rgba(0, 0, 0, 0.7)",
        });
        copyBigscreen(item.lgc_sn).then(res => {
          if (res.tx_status === "00") {
            this.$message.success(`大屏复制成功！`);
            this.queryByPage();
          } else {
            this.$message.error(res.error_info.msg || "请求失败");
          }
        }).finally(() => {
          loading.close();
        })
      })
    }
  },
};
</script>

<style lang="less">
.main-layout {
  .contadd {
    overflow: hidden;
    .block {
      float: left;
      margin: 40px 0 0 40px;
      .el-pagination__total {
        color: #fff;
      }
      .el-select .el-input .el-input__inner {
        background: #0f1014;
        color: #fff;
        border: 1px solid #409eff;
      }
      .btn-prev, .btn-next {
        background: #0f1014;
        color: #fff;
      }
      .el-pager li {
        background: #0f1014;
        color: #fff;
      }
      .el-pagination__jump {
        color: #fff;
        .el-input__inner {
          background: #0f1014;
          color: #fff;
          border: 1px solid #409eff;
        }
      }
    }
  }
  .navbg {
    width: 100%;
    height: 160px;
    background: url('../../assets/images/nav-img.png') no-repeat;
    background-size: 100% 100%;
    .input-with-select {
      position:absolute;
      top: 60px;
      left: 25%;
      width: 50%;
      height: 40px;
      margin: 0 auto;
      .el-input__inner {
        height: 40px;
        line-height: 40px;
      }
    }
    .checkobx {
      position:absolute;
      top: 120px;
      left: 25%;
      width: 50%;
    }

  }
  position: relative;
  height: 100vh;
  background: #171b22;
  header {
    text-align: center;
    .title {
      font-size: 24px;
      padding: 20px 0 10px 0;
    }
    .time {
      font-size: 16px;
    }
  }
  .bg {
    width: 100%;
    height: 200px;
    position: relative;
    overflow: hidden;
    margin: 10px 0;
    border: 12px solid white;
  }

  .bg .bg-img {
    position: absolute;
    width: 100%;
    height: 100%;
    filter: blur(6px);
    z-index: 2;
  }
  .empty {
    border: 1px solid #dadada;
    border-radius: 6px;
    min-height: 200px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 20px;
  }
  .content {
    width: 100%;
    height: 100%;
    position: absolute;
    color: #fff;
    left: 0;
    top: 0;
    z-index: 3;
  }
  footer {
    width: 100%;
    font-size: 14px;
    padding: 16px;
    line-height: 30px;
    position: absolute;
    z-index: 3;
    bottom: 0;
    .operation {
      width: 100%;
      span {
        float: left;
      }
      .view,
      .edit {
        color: #fff;
        font-size: 14px;
        float: right;
      }
      .el-button {
        padding: 7px 10px;
      }
    }
  }
  .dialogStyle .el-dialog__body {
    padding: auto 80px;
  }
  .content__add {
    margin: 20px 0 10px 20px;
    width: 280px;
    height: 78px;
    padding: 0 20px;
    float: left;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    vertical-align: middle;
    border: 1px solid #00baff;
    color: #8eeeff;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-pack: start;
    -ms-flex-pack: start;
    justify-content: flex-start;
    position: relative;
    background-image: -webkit-gradient(
      linear,
      right top,
      left top,
      color-stop(0, rgba(0, 222, 255, 0.39)),
      to(rgba(0, 174, 255, 0.19))
    );
    background-image: linear-gradient(
      -90deg,
      rgba(0, 222, 255, 0.39),
      rgba(0, 174, 255, 0.19)
    );
    -webkit-box-shadow: 0 0 10px 0 rgba(55, 224, 255, 0.3);
    box-shadow: 0 0 10px 0 rgba(55, 224, 255, 0.3);
    font-size: 14px;
    cursor: pointer;
    p {
      margin-left: 20px;
    }
  }
  .content__item {
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -ms-flex-direction: column;
    flex-direction: column;
    position: relative;
    width: 280px;
    height: 184px;
    border: 1px solid #3a4659;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    overflow: hidden;
    .content__info {
      position: relative;
      height: calc(100% - 36px);
      .title {
        position: absolute;
        font-size: 24px;
        top: 20px;
        left: 50%;
        transform: translateX(-50%);
        color: #fff;
      }
      .time {
        font-size: 16px;
        position: absolute;
        top: 60px;
        left: 50%;
        transform: translateX(-50%);
        color: #fff;
        width: 150px;
      }
      img {
        width: 280px;
        height: 186px;
        filter: blur(3px);
      }
      .jietu {
        position: relative;
        width: 382px;
        height: 190px;
        transform: scale(2);
        transform: scale(1.5);
        top: 46px;
        left: 71px;
      }
      .content__menu {
      position: absolute;
      top: 0;
      left: 0;
      background-color: rgba(29,38,46,.8);
      width: 100%;
      height: 100%;
      display: -webkit-box;
      display: -ms-flexbox;
      display: flex;
      -webkit-box-align: center;
      -ms-flex-align: center;
      align-items: center;
      -webkit-box-pack: center;
      -ms-flex-pack: center;
      justify-content: center;
      -webkit-box-orient: vertical;
      -webkit-box-direction: normal;
      -ms-flex-direction: column;
      flex-direction: column;
      .content__btn {
        margin: 5px 0;
        display: inline-block;
        vertical-align: middle;
        height: 34px;
        line-height: 34px;
        padding: 0 40px;
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
        outline: 0;
        text-align: center;
        font-size: 14px;
        background-image: linear-gradient(-225deg,#00d3f1,#12b3ff);
        background-color: #2681ff;
        border-color: #2681ff;
        color: #fff;
        border: none;
        -webkit-transition: .3s ease;
        transition: .3s ease;
        cursor: pointer;
      }
    }
    }
    .content__main {
      font-size: 12px;
      width: 280px;
      height: 36px;
      display: -webkit-box;
      display: -ms-flexbox;
      display: flex;
      -webkit-box-align: center;
      -ms-flex-align: center;
      align-items: center;
      position: absolute;
      bottom: 0;
      -webkit-box-pack: justify;
      -ms-flex-pack: justify;
      justify-content: space-between;
      background: #1d262e;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      padding: 0 10px;
      color: #bcc9d4;
      .content__name {
        width: 100px;
        padding: 0 5px;
        line-height: 28px;
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
        border: 1px solid transparent;
      }
      .content__menulist {
        display: flex;
        .content__view {
          margin-right: 2px;
          .operation {
            width: 255px;
            overflow: hidden;
            span {
              float: right;
              display: block;
              line-height: 30px;
            }
            .view,
            .edit {
              color: #fff;
              font-size: 14px;
              float: left;
            }
            .el-button {
              padding: 7px 6px;
            }
          }
        }
      }
    }
  }
}
</style>
